#ifndef SERIESINSTANCE_H
#define SERIESINSTANCE_H

#include <QObject>
#include <QMap>
#include "dcmtk/dcmimgle/diutils.h"
#include "../Global/structs.h"
class DicomImage;
class ImageInstance;
class DcmTagKey;

class SeriesInstance: public QObject
{
    Q_OBJECT
public:
    explicit SeriesInstance(const QString &seriesUID, QObject *parent = 0);
    ~SeriesInstance();

    bool insertImage(ImageInstance *image);
    bool removeImage(const QString &imgFile);
    int count() const { return imageMap.count(); }
    bool isEmpty() const { return imageMap.isEmpty(); }
    bool hasImage(const QString &file);
    QString getTagKeyValue(const DcmTagKey &key) const;
    int getFrameCount(ViewType type) const;

    const short **getSeriesVolume(const short **&volume, ulong &width, ulong &height, ulong &slice);
    const ushort **getRawVolume(const ushort **&volume, ulong &width, ulong &height, ulong &slice);
    ImageInstance *getCurrImageInstance(ViewType type) const;
    bool getPixmap(QPixmap &pixmap, ViewType type);
    void nextFrame(ViewType type);
    void prevFrame(ViewType type);
    void gotoFrame(int index, ViewType type);
    int getCurIndex(ViewType type);

    void setWindow(const double &center, const double &width)
    { winCenter = center; winWidth = width; }
    void getWindow(double &center, double &width) const
    { center = winCenter; width = winWidth; }
    void setWindowDelta(const double &dCenter, const double &dWidth)
    { winCenter += dCenter; winWidth += dWidth; }
    void setRoiWindow(const QRectF &rect);
    void setDefaultWindow()
    {  winCenter = defCenter; winWidth = defWidth; }
    void setFullDynamic();

    void setPolarity(EP_Polarity polarity);
    EP_Polarity getPolarity() const { return pola; }
    double getPixelValue(long x, long y, ViewType type) const;
    bool getPixSpacing(double &spacingX, double &spacingY, ViewType type) const;
    inline void delVolBuffer();

signals:
    void aboutToDelete();

private:
    SeriesInstance(const SeriesInstance &);
    SeriesInstance &operator= (const SeriesInstance &);

    QString seriesUid;
    int curXYFrame;
    int curXZFrame;
    int curYZFrame;
    ulong imgWidth;
    ulong imgHeight;
    double winCenter;
    double winWidth;
    double defCenter;
    double defWidth;
    EP_Polarity pola;
    const short **volPtr;
    ulong volSlice;
    const ushort **rawPtr;
    ulong rawSlice;
    QMap<int, ImageInstance*> imageMap;
};

#endif // SERIESINSTANCE_H
